module.exports = function(sequelize, DataTypes) {
    const workflow = sequelize.define('workflow', {
        id: {
            type: DataTypes.INTEGER(20).UNSIGNED,
            autoIncrement: false,
            allowNull: false,
            primaryKey: true
        },
        item_type: {
            type: DataTypes.STRING
        },
        organization_id: {
            type: DataTypes.INTEGER(20).UNSIGNED
        },

        step: {
            type: DataTypes.ENUM,
            allowNull: false,
            values: [
                'preparation',
                'precheck',
                'precheck_pass',
                'precheck_reject',
                'complete',
                'complete_part',
                'complete_pass',
                'postcheck',
                'postcheck_pass',
                'postcheck_reject'
            ],
            defaultValue: 'preparation'
        },
        locked_by: {
            type: DataTypes.INTEGER(20).UNSIGNED
        },
        locked_at: {
            type: DataTypes.DATE
        },

        pre_check_at: {
            type: DataTypes.DATE
        },
        pre_check_by: {
            type: DataTypes.INTEGER(20).UNSIGNED
        },

        post_check_at: {
            type: DataTypes.DATE
        },
        post_check_by: {
            type: DataTypes.INTEGER(20).UNSIGNED
        },

        complete_progress: {
            type: DataTypes.INTEGER(3)
        },

        created_at: {
            type: DataTypes.DATE
        },
        updated_at: {
            type: DataTypes.DATE
        }
    }, {
        tableName: 'sophic_workflows',

        underscored: true,

        indexes: [{
            fields: ['step']
        }, {
            fields: ['locked_by']
        }, {
            fields: ['created_at']
        }, {
            fields: ['updated_at']
        }]
    })

    return workflow
}